package cn.edu.scau.cmi.mingjunhui.composite.consistent;

import java.util.Set;

public class ConsistentLeaf extends ConsistentComponent {

	public ConsistentLeaf(ConsistentComponent org, String name) {
		super(org, name);
	}

	@Override
	public ConsistentComponent addChild(ConsistentComponent child) {
		System.out.println("这不是组织，无法增加成员，增加失败");
		return this;
	}

	@Override
	public Set<ConsistentComponent> getChild() {
		System.out.println("这不是组织，不含成员，获取失败");
		return null;
	}

	@Override
	public ConsistentComponent deleteChild(ConsistentComponent child) {
		System.out.println("这不是组织，不含成员,删除失败");
		return null;
	}
	@Override
	public String toString(int pos) {
		// TODO Auto-generated method stub
		String parentName = getParent() == null ? "无" : getParent().getName();
		String blank = "";
		for (int i=0; i<pos; i++) blank += " ";
		return  blank + "\"" + getName() + "\": {\n"
				+ blank + "	\"类型\": \"个人\",\n"
				+ blank + "	\"父亲\": \"" + parentName + "\"\n"
				+ blank + "}\n";
	}
	@Override
	public String toString() {
		return toString(0);
	}
	
	@Override
	public ConsistentComponent get(String tarName) {
		// TODO Auto-generated method stub
		if(this.name.equals(tarName)) return this;
		return null;
	}
	
	@Override
	public void setParent(ConsistentComponent p)
	{
		this.parent = p;
	}

}
